package com.aw.baselib.adapter;

import com.aw.baselib.R;
import com.aw.baselib.bean.CommonListBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hzw.
 */

public class CommonListBlueAdapter extends BaseQuickAdapter<CommonListBean, BaseViewHolder> {

    private List<? extends CommonListBean> mList = new ArrayList<>();

    public CommonListBlueAdapter() {
        super(R.layout.view_item_common_blue_pupupwidow);
        if(mList == null) {
            mList = new ArrayList<>();
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, final CommonListBean bean) {
        if(bean == null) {
            return;
        }
        helper.setText(R.id.tv_name, bean.getItemName());
    }

    public void addAllData(List<? extends CommonListBean> dataList) {
        this.mList = dataList;
        this.setNewData((List<CommonListBean>) mList);
        notifyDataSetChanged();
    }

    public void clearData() {
        if(mList != null) {
            int startPosition = 0;//hasHeader is 1
            int preSize = this.mList.size();
            if(preSize > 0) {
                this.mList.clear();
                notifyItemRangeRemoved(startPosition, preSize);
            }
        }
    }
}
